package com.projects.modular.realty.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.projects.core.common.page.LayuiPageInfo;
import com.projects.modular.realty.entity.Child;
import com.projects.modular.realty.model.params.ChildParam;
import com.projects.modular.realty.service.ChildService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * 家庭成员控制器
 *
 * @author 曾大顺
 * @since 2025-02-11
 */
@RestController
@RequestMapping("/api/child")
@Api(tags = "家庭成员管理")
public class ChildController extends BaseController {

    @Autowired
    private ChildService childService;


    /**
     * 新增接口
     *
     * @author 曾大顺
     * @since 2025-02-11
     */
    @ApiOperation("新增家庭成员")
    @PostMapping("/addChild")
    public ResponseData addChild(@RequestBody ChildParam childParam) {
        this.childService.add(childParam);
        return ResponseData.success("添加成功");
    }

    /**
     * 编辑接口
     *
     * @author 曾大顺
     * @since 2025-02-11
     */
    @ApiOperation("编辑家庭成员")
    @PostMapping("/editChild")
    public ResponseData editChild(@RequestBody ChildParam childParam) {
        this.childService.update(childParam);
        return ResponseData.success("修改成功");
    }


    /**
     * 删除接口
     *
     * @author 曾大顺
     * @since 2025-02-11
     */
    @ApiOperation("删除家庭成员")
    @GetMapping("/deleteById")
    public ResponseData deleteById(@RequestParam String childId) {
        this.childService.deleteById(childId);
        return ResponseData.success("删除成功");
    }

    /**
     * 查看详情接口
     *
     * @author 曾大顺
     * @since 2025-02-11
     */
    @ApiOperation("查看家庭成员详情")
    @GetMapping("/detail")
    public ResponseData detail(@RequestParam String childId) {
        Child detail = this.childService.getById(childId);
        return ResponseData.success(detail);
    }

    /**
     * 根据用户ID查询所有成员信息
     *
     * @author 曾大顺
     * @since 2025-02-11
     */
    @GetMapping("/listByUserId")
    @ApiOperation("根据用户ID查询所有成员信息")
    public ResponseData listByUserId(@RequestParam String userId) {
        List<Child> children = this.childService.getByUserId(userId);
        return ResponseData.success(children);
    }

    /**
     * 激活接口
     *
     */
    @ApiOperation("激活家庭成员")
    @GetMapping("/updateActive")
    public ResponseData updateActive(@RequestParam String childId) {
        return this.childService.updateActive(childId);
    }

}
